//
//  LCMineViewController.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/9/6.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCMineViewController.h"
#import "LCMineHeadCell.h"
#import "LCYaoQingHtmlVC.h"
#import "LSZCollectVC.h"//收藏
#import "MyNotesViewController.h"//笔记
 

#define mineCell_ID @"mineOthersCell_ID"
#define mineHeadCell_ID @"mineHeadCell_ID"
//#define mineSettingCell_ID @"mineSettingCell_ID"

@interface LCMineViewController ()<UINavigationControllerDelegate,UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate>
{
    BOOL isOrInvite;//是否邀请过  yes  邀请过   no没邀请
    NSArray *arrayNotInvite;
    NSArray *arrayInvite;

    NSArray * arrayExplain;

}
@property (nonatomic,strong) UITableView *tableView;//

@property (nonatomic,strong) NSArray *array;//
@end

@implementation LCMineViewController
#pragma mark - 获取用户的信息
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [LCFloatingWindow sharedInstance].hidden = YES;
    __weak typeof(self) weakSelf = self;
    if (iPhoneX) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    else{
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        self.navigationController.delegate = self;
    }
    if ([[_UserM usercode] isEqualToString:@""]) {
        isOrInvite = NO;
        [weakSelf.tableView reloadData];
    }else{
        //获取用户的信息
        __weak typeof(self) weakSelf = self;
        [LSZRequestResolutionDic initWithGetUserInformation:^(BOOL isOK, NSString * str, LSZPersonalInformationManager * manager) {
            if (isOK == YES) {
                weakSelf.informationMg = manager;
                LSZPersonalInformationMg * information = nil;
                information = self.informationMg.mutDataArray[0];
                if ([information.hid integerValue] >0) {
                    self->isOrInvite = YES;
                }else{
                    self->isOrInvite = NO;
                }
                [weakSelf.tableView reloadData];
            }else{
                [self setStringWarning:str];
            }
        }];
    }
}
-(void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = nil;
    if (iPhoneX) {
        self.navigationController.navigationBar.prefersLargeTitles = NO;
    }
    else{
        self.navigationController.delegate = self;
    }
    [self loadData];
    [self haoping];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    if(iPhoneX){
        self.tableView.frame =CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height-TAB_BAR_HEIGHT);
    }
    else{
        UIView * viewTop = [[UIView alloc]init];
        viewTop.frame = CGRectMake(0, 0, ScreenWidth, STATUS_BAR_HEIGHT);
        viewTop.backgroundColor =  [UIColor colorWithRed:0.93 green:0.45 blue:0.44 alpha:1.00];
        [self.view addSubview:viewTop];
        self.tableView.frame =CGRectMake(0,CGRectGetMaxY(viewTop.frame),self.view.frame.size.width, self.view.frame.size.height-CGRectGetMaxY(viewTop.frame)-TAB_BAR_HEIGHT);
    }
    self.tableView.bounces = NO;//取消回弹
    //    self.tableView.showsHorizontalScrollIndicator = NO;//禁用滚动指示器 滚动条
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.sectionFooterHeight = 5.5;
    //    [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
#pragma mark - UITableVIewCell隐藏 多余的线 - 下午4:36
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    //添加以下代码关闭估算行高
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.separatorColor = divider;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
    [self.tableView registerClass:[LCMineHeadCell class] forCellReuseIdentifier:mineHeadCell_ID];
    [self.tableView registerClass:[LSZInvitationTableViewCell class] forCellReuseIdentifier:@"LSZInvitationTableViewCell"];
    [self.tableView registerClass:[LSZSharingTypeTableViewCell class] forCellReuseIdentifier:@"LSZSharingTypeTableViewCell"];
    [self.tableView registerClass:[LSZMyHeaderCell class] forCellReuseIdentifier:@"LSZMyHeaderCell"];
//    [self setupDayHongBao];

     self.adViewArray = [[NSMutableArray alloc]init];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationSuccessfully) name:@"addedSuccessfullyMine" object:nil];
}
-(void)InfoNotificationSuccessfully
{
    [self.tableView reloadData];
}
- (void)loadData{
    arrayNotInvite = @[
                       @{@"img":@"我的_输入邀请码",@"title":@"输入邀请码"},
                       @{@"img":@"我的_祷告见证",@"title":@"我的祷告见证"},
                       @{@"img":@"更多",@"title":@"更多圣经"},
                       @{@"img":@"我的文章",@"title":@"我的文章"},
                       @{@"img":@"意见反馈",@"title":@"意见反馈"},
                       @{@"img":@"i_icon_shezhi",@"title":@"设置中心"}
                       ];
    arrayInvite = @[
                    @{@"img":@"我的_祷告见证",@"title":@"我的祷告见证"},
                    @{@"img":@"更多",@"title":@"更多圣经"},
                    @{@"img":@"我的文章",@"title":@"我的文章"},
                    @{@"img":@"意见反馈",@"title":@"意见反馈"},
                    @{@"img":@"i_icon_shezhi",@"title":@"设置中心"}
                    ];

    arrayExplain = @[@"微信,支付宝,手机充值",@"输入后奖励500福音值"];
}
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:false];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 2) {
        if (isOrInvite == YES) {
            return arrayInvite.count;
        }else{
            return arrayNotInvite.count;
        }
    }else if(section == 1){
        return 2;
    }
    return 1;
}
#pragma mark -  UITableViewDelegate  -
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (ScreenWidth == 320) {
            //5
            return 250;
        }else if(ScreenWidth == 375){
            // 6 7
            return 260;
        }else {
            //plus
            return 268;
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            if (ScreenWidth == 320) {
                //5
                return 58.5;
            }else if(ScreenWidth == 375){
                // 6 7
                return 65;
            }else {
                //plus
                return 71.5;
            }
        }else{
            if (ScreenWidth == 320) {
                //5
                return 54;
            }else if(ScreenWidth == 375){
                // 6 7
                return 60;
            }else {
                //plus
                return 68;
            }
        }
    }
    else{
        if (ScreenWidth == 320) {
            //5
            return 45;
        }else if(ScreenWidth == 375){
            // 6 7
            return 50;
        }else {
            //plus
            return 58;
        }
    }
}
#pragma mark - 下午4:01 组高度 -
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.00001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        return 50;
    }else{
        return 10;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UITableViewHeaderFooterView * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"cell"];
    }
    return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0&&indexPath.row == 0){
        LCMineHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:mineHeadCell_ID forIndexPath:indexPath];
        [self initWithCellForRow:indexPath :cell];
        return cell;
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            LSZInvitationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZInvitationTableViewCell" forIndexPath:indexPath];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        LSZSharingTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LSZSharingTypeTableViewCell" forIndexPath:indexPath];
        [cell.butCircleFriends addTarget:self action:@selector(clickCircleFriends) forControlEvents:UIControlEventTouchUpInside];
        [cell.butMicroLetter addTarget:self action:@selector(clickMicroLetter) forControlEvents:UIControlEventTouchUpInside];
        [cell.butQQ addTarget:self action:@selector(clickQQ) forControlEvents:UIControlEventTouchUpInside];
        [cell.butQrCode addTarget:self action:@selector(clickQrCode) forControlEvents:UIControlEventTouchUpInside];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } 
    else{
        LSZMyHeaderCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZMyHeaderCell" forIndexPath:indexPath];
        if (isOrInvite == YES) {
            cell.imageViewIcon.image = [UIImage imageNamed:arrayInvite[indexPath.row][@"img"]];
            cell.labelTitle.text = arrayInvite[indexPath.row][@"title"];
            cell.labelExplain.hidden = YES;

//            CGRect rect = cell.imageViewIcon.frame;
//            rect.size.height =  rect.size.width;
//            cell.imageViewIcon.frame = rect;
        }else{
            cell.imageViewIcon.image = [UIImage imageNamed:arrayNotInvite[indexPath.row][@"img"]];
            cell.labelTitle.text = arrayNotInvite[indexPath.row][@"title"];
            cell.labelExplain.hidden = YES;
//            CGRect rect = cell.imageViewIcon.frame;
//            rect.size.height =  rect.size.width;
//            cell.imageViewIcon.frame = rect;
        }
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
#pragma mark - 第一个区
-(void)initWithCellForRow :(NSIndexPath *)indexPath :(LCMineHeadCell *)cell
{
    LSZPersonalInformationMg * information = nil;
    information = self.informationMg.mutDataArray[0];
    if ([[_UserM usercode] isEqualToString:@""]){
        cell.imageViewHeader.image = [UIImage imageNamed:@"placeholder"];
        cell.labelUserName.hidden = YES;
        cell.viewTimeTotal.hidden = YES;
        cell.butNoLogin.hidden = NO;
        cell.labelLove.text = @"爱心值 0.00";
        cell.labelFuYin.text = @"福音值 0.00";
        CGFloat lovelabel = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelLove sizeMaxWidth:ScreenWidth/2];
        CGFloat fuYinLabel = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelFuYin sizeMaxWidth:ScreenWidth/2];
        cell.labelLove.frame = CGRectMake((ScreenWidth/2-lovelabel)/2, cell.labelLove.frame.origin.y, lovelabel, cell.labelLove.frame.size.height);
        cell.labelFuYin.frame = CGRectMake((ScreenWidth/2-fuYinLabel)/2, cell.labelFuYin.frame.origin.y, fuYinLabel, cell.labelFuYin.frame.size.height);

        CGRect rect = cell.imageViewLove.frame;
        rect.origin.x = CGRectGetMinX(cell.labelLove.frame)-cell.imageViewLove.frame.size.width-2;
        cell.imageViewLove.frame = rect;

        CGRect rect2 = cell.imageViewFuYin.frame;
        rect2.origin.x = CGRectGetMinX(cell.labelFuYin.frame)-cell.imageViewFuYin.frame.size.width-2;
        cell.imageViewFuYin.frame = rect2;

        [cell.butNoLogin addTarget:self action:@selector(gotoLogIn) forControlEvents:UIControlEventTouchUpInside];
    }
    else{
        cell.butNoLogin.hidden = YES;
        cell.viewTimeTotal.hidden = NO;
        cell.labelUserName.hidden = NO;

        cell.imageViewHeader.image = [UIImage imageNamed:@"placeholder"];
        cell.labelReading.text = [NSString stringWithFormat:@"今日阅读%ld分钟",(long)_UserM.readingTime];
        _UserM.getReadTimeBlock = ^(NSInteger readingTime) {
            cell.labelReading.text = [NSString stringWithFormat:@"今日阅读%ld分钟",(long)readingTime];
        };
        NSString * State = NullStringjudgment([[NSUserDefaults standardUserDefaults]objectForKey:@"headerPhoto"]);
        NSLog(@"%@>>>>>>>>>>>>头像",State);
        NSString * avatar = NullStringjudgment(information.avatar);
        if (![avatar isEqualToString:@""] && ![State isEqualToString:@""]){
            [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:State] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        }
        else if (![avatar isEqualToString:@""] && [State isEqualToString:@""]){
            [self LinkStorageOfImages:information.avatar];
            [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:information.avatar] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        }
        else{
            cell.imageViewHeader.image = [UIImage imageNamed:@"login_uploadbg"];
        }

        NSString * nameStr =  NullStringjudgment(NSStr(information.username));
        if ([nameStr isEqualToString:@""]||nameStr.length == 0) {
            if ([ NullStringjudgment(NSStr(information.uid)) isEqualToString:@""]) {
                cell.labelUserName.text = @"";
            }else{
                cell.labelUserName.text = [NSString stringWithFormat:@"fy_%@",NullStringjudgment(NSStr(information.uid))];
            }
        }else{
            cell.labelUserName.text = [NSString stringWithFormat:@"%@",NullStringjudgment(NSStr(information.username))];
        }
        if([NullStringjudgment(NSStr(information.score)) isEqualToString:@""]){
            cell.labelLove.text = @"爱心值 0.00";
        }else{
            cell.labelLove.text = [NSString stringWithFormat:@"爱心值 %@",NullStringjudgment(NSStr(information.score))];
        }
        if([NullStringjudgment(NSStr(information.credit)) isEqualToString:@""]){
            cell.labelFuYin.text = @"福音值 0.00";
        }else{
            cell.labelFuYin.text = [NSString stringWithFormat:@"福音值 %@",NullStringjudgment(NSStr(information.credit))];
        }

        CGFloat lovelabel = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelLove sizeMaxWidth:ScreenWidth/2];
        CGFloat fuYinLabel = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelFuYin sizeMaxWidth:ScreenWidth/2];
        cell.labelLove.frame = CGRectMake((ScreenWidth/2-lovelabel)/2, cell.labelLove.frame.origin.y, lovelabel, cell.labelLove.frame.size.height);
        cell.labelFuYin.frame = CGRectMake((ScreenWidth/2-fuYinLabel)/2, cell.labelFuYin.frame.origin.y, fuYinLabel, cell.labelFuYin.frame.size.height);

        CGRect rect = cell.imageViewLove.frame;
        rect.origin.x = CGRectGetMinX(cell.labelLove.frame)-cell.imageViewLove.frame.size.width-2;
        cell.imageViewLove.frame = rect;

        CGRect rect2 = cell.imageViewFuYin.frame;
        rect2.origin.x = CGRectGetMinX(cell.labelFuYin.frame)-cell.imageViewFuYin.frame.size.width-2;
        cell.imageViewFuYin.frame = rect2;

    }
    [cell.butNotice addTarget:self action:@selector(clicMyNotice)  forControlEvents:UIControlEventTouchUpInside];

    [cell.butSetUp addTarget:self action:@selector(clicMyInformation)  forControlEvents:UIControlEventTouchUpInside];
    [cell.imageViewHeader tapGesture:^(UIGestureRecognizer *ges) {
        [self changeThePicture];
    }];
    [cell.butInviteCode addTarget:self action:@selector(clickSignIn) forControlEvents:UIControlEventTouchUpInside];
    [cell.butFuYin addTarget:self action:@selector(clickValueFY) forControlEvents:UIControlEventTouchUpInside];
    [cell.butLove addTarget:self action:@selector(clickLoveBut) forControlEvents:UIControlEventTouchUpInside];
    //兑换提现
    [cell.butSignIn addTarget:self action:@selector(butClickExchange) forControlEvents:UIControlEventTouchUpInside];
    [cell.labelSignIn tapGesture:^(UIGestureRecognizer *ges) {
        [self butClickExchange];
    }];
    [cell.imageViewSignIn tapGesture:^(UIGestureRecognizer *ges) {
        [self butClickExchange];
    }];
    //收藏
    [cell.butCollection addTarget:self action:@selector(clickCollection) forControlEvents:UIControlEventTouchUpInside];
    [cell.labelCollection tapGesture:^(UIGestureRecognizer *ges) {
        [self clickCollection];
    }];
    [cell.imageViewCollection tapGesture:^(UIGestureRecognizer *ges) {
        [self clickCollection];
    }];
    //历史记录
    [cell.butHistorical addTarget:self action:@selector(clickHistorical) forControlEvents:UIControlEventTouchUpInside];
    [cell.labelHistorical tapGesture:^(UIGestureRecognizer *ges) {
        [self clickHistorical];
    }];
    [cell.imageViewHistorical tapGesture:^(UIGestureRecognizer *ges) {
        [self clickHistorical];
    }];
    //缓存
    [cell.butCache addTarget:self action:@selector(clickCache) forControlEvents:UIControlEventTouchUpInside];
    [cell.labelCache tapGesture:^(UIGestureRecognizer *ges) {
        [self clickCache];
    }];
    [cell.imageViewCache tapGesture:^(UIGestureRecognizer *ges) {
        [self clickCache];
    }];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
#pragma mark - 把上传的图片的链接存储在本地
-(void)LinkStorageOfImages :(NSString *)url
{
    //    获取当前时间的毫秒数
    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
    [formatter setDateFormat:@"YYYYMMddhhmmssSSS"];
    NSString * date = [formatter stringFromDate:[NSDate date]];
    NSString * timeNow = [[NSString alloc] initWithFormat:@"%@", date];
    //八位随机数
    NSString * strRandom = @"";
    for (int i=0; i<3; i++) {
        strRandom = [strRandom stringByAppendingFormat:@"%i",(arc4random() % 9)];
    }
    NSString * imageNameStr = [NSString stringWithFormat:@"%@?%@%@",url,timeNow,strRandom];
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:imageNameStr forKey:@"headerPhoto"];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 1 && indexPath.row == 0){
        if ( [[_UserM usercode] isEqualToString:@""]) {
            [self gotoLogIn];
        }else{
            LCYaoQingHtmlVC *yaoQingHtmlVC = [[LCYaoQingHtmlVC alloc] init];
            [self.navigationController pushViewController:yaoQingHtmlVC animated:YES];
        }
    }
    else if ((indexPath.row == 2&&isOrInvite == NO)||(indexPath.row == 1&&isOrInvite == YES)){
        //今日圣经
        NSString * url = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/cn/app/id%@?mt=8",@"1342123382"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }
    else if ( (indexPath.row == 5&&isOrInvite == NO)||(indexPath.row == 4&&isOrInvite == YES)){
        [self clickSheZhi];
    }
    else  if (indexPath.section == 2) {
        if ( [[_UserM usercode] isEqualToString:@""]) {
            [self gotoLogIn];
        }else{
            if (indexPath.row == 0&&isOrInvite == NO){
                LSZEnterInvitationCodeViewController * VC = [[LSZEnterInvitationCodeViewController alloc]init];
                [self.navigationController pushViewController:VC animated:YES];
            }else if ((indexPath.row == 1&&isOrInvite == NO)||(indexPath.row == 0&&isOrInvite == YES)){
                //我要祷告
                LSZNewPrayToWitnessVC * vc = [[LSZNewPrayToWitnessVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }
            else if ( (indexPath.row == 3&&isOrInvite == NO)||(indexPath.row == 2&&isOrInvite == YES)){
                NSString *clzName = @"LCCreateWenHtmlVC";
                Class clz = NSClassFromString(clzName);
                LCViewController *viewController = [[clz alloc] init];
                viewController.vcInitDictData = [NSDictionary dictionaryWithObjectsAndKeys:@"添加文章", @"title",
                                                 [NSString stringWithFormat:@"http://fuyin-admin.app.inping.com/home/edit/ad?usercode=%@",[_UserM usercode]], @"link", @"我的文章", @"rightTitle", nil];
                [self.navigationController pushViewController:viewController animated:YES];
                return;
            }
            else if ( (indexPath.row == 4&&isOrInvite == NO)||(indexPath.row == 3&&isOrInvite == YES)){
                //用户反馈
                SuggestMessageViewController * suggestVC = [[SuggestMessageViewController alloc] init];
                [self.navigationController pushViewController:suggestVC animated:YES];
            }
            else{
                NSLog(@"11111");
            }
        }
    }
}
#pragma mark -------------------分享---------------------
#pragma mark - 朋友圈
-(void)clickCircleFriends
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享朋友圈"];
}
#pragma mark -好友
-(void)clickMicroLetter
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享微信"];
}
#pragma mark - qq
-(void)clickQQ
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享QQ"];
}
#pragma mark - 二维码
-(void)clickQrCode
{
    if ([[_UserM usercode] isEqualToString:@""]) {
        [self gotoLogIn];
    }else{
        LSZQrCodeViewController * VC= [[LSZQrCodeViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}
#pragma mark - _______________________界面跳转________________
#pragma mark - 跳转到福音值界面
-(void)clickValueFY
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LSZPersonalInformationMg * information = nil;
        information = self.informationMg.mutDataArray[0];
        LSZMyGospelValueViewController * vc = [[LSZMyGospelValueViewController alloc]init];
        vc.stringValue = information.credit;
        if ([information.hid integerValue] >0) {
            vc.isInviteCode = NO;
        }else{
            vc.isInviteCode = YES;
        }
        [self.navigationController pushViewController:vc animated:YES];
        //        WYWebController *webVC = [WYWebController new];
        //        webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/my_fyz?usercode=%@",[_UserM usercode]];
        //        [self.navigationController pushViewController:webVC animated:YES];
    }
}
#pragma mark - 爱心值的点击事件
-(void)clickLoveBut
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        WYWebController *webVC = [WYWebController new];
        webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/axz_rank"];
        [self.navigationController pushViewController:webVC animated:YES];
    }
}
#pragma mark - 跳转到动态消息界面
-(void)clicMyNotice
{
    LSZNotifyClassificationVC * vc = [[LSZNotifyClassificationVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 跳转到个人信息的地方
-(void)clicMyInformation
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LSZPersonalInformationVC * VC = [[LSZPersonalInformationVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}
#pragma mark- 跳转登陆界面
-(void)gotoLogIn
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }
}
#pragma mark - 设置
-(void)clickSheZhi
{
    //设置
    SettingViewController * VC = [[SettingViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}
#pragma mark - 邀请码
-(void)clickInviteCode
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LCYaoQingHtmlVC *yaoQingHtmlVC = [[LCYaoQingHtmlVC alloc] init];
        [self.navigationController pushViewController:yaoQingHtmlVC animated:YES];
    }
}
#pragma mark - 邀请有奖
-(void)clickInvitation
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        Class clz = NSClassFromString(@"LCYaoQingHtmlVC");
        UIViewController *yaoQingHtmlVC = [[clz alloc] init];
        [self.navigationController pushViewController:yaoQingHtmlVC animated:YES];
    }
}
#pragma mark - 兑换
-(void)butClickExchange
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LSZExchangeVC * vc = [[LSZExchangeVC alloc]init];
        LSZPersonalInformationMg * information = nil;
        information = self.informationMg.mutDataArray[0];
        vc.fuYinValue = NullStringjudgment(NSStr(information.credit));
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - 订单详情
-(void)butClickOrder
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        WYWebController *webVC = [WYWebController new];
        webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/my_dedication?usercode=%@",[_UserM usercode]];
        [self.navigationController pushViewController:webVC animated:YES];
        return;
    }
}
#pragma mark - 签到
-(void)clickSignIn
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LSZDailyCheckViewController * vc =  [[LSZDailyCheckViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark- 收藏
-(void)clickCollection
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        // 收藏
        LSZCollectVC * VC = [[LSZCollectVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}
#pragma mark - 笔记
-(void)clickHistorical
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        MyNotesViewController * myNotesVC = [[MyNotesViewController alloc] init];
        [self.navigationController pushViewController:myNotesVC animated:YES];
    }
}
#pragma mark - 缓存
-(void)clickCache
{
    LSZVideoOfflineCacheVC * vc = [[LSZVideoOfflineCacheVC alloc]init];
    vc.title = @"离线视频";
    vc.isOkOffline = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
///弹出好评
- (void)haoping {
    //    if([SKStoreReviewController respondsToSelector:@selector(requestReview)]){
    //        [SKStoreReviewController requestReview];
    //    }else{
    if (![self startFifteen]) {//非启动十五次
        return;
    }
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示"
                                                                   message:@"给个五星好评吧亲! "
                                                            preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *feedbackAction = [UIAlertAction actionWithTitle:@"我要吐槽o(╯□╰)o" style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction * action) {
                                                               SuggestMessageViewController * vc = [[SuggestMessageViewController alloc]init];
                                                               [self.navigationController pushViewController:vc animated:YES];
                                                           }];
    [alert addAction:feedbackAction];
    NSString *cancelStr = @"看看再说!(>_<)";
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelStr style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"五星好评(^_^)" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              NSString  *nsStringToOpen = [NSString  stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",@"1342123382"];//替换为对应的APPID
                                                              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
                                                          }];
    [alert addAction:cancelAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 启动次数是否满足好评条件
- (Boolean)startFifteen {
    //根据版本号判断是否第15次启动,弹出好评
    NSUserDefaults* defaulut = [NSUserDefaults standardUserDefaults];
    // 从沙盒中读取上一次存储的手机版本号
    NSInteger num = [defaulut integerForKey:@"HAOPING"];
    NSString* lastVersion = [defaulut objectForKey:@"appVersion"];
    // 获取当前的手机应用版本号
    NSDictionary* dict = [NSBundle mainBundle].infoDictionary;
    NSString* appVersion = dict[@"CFBundleShortVersionString"];
    [defaulut setInteger:num+1 forKey:@"HAOPING"];//存储次数
    [defaulut setObject:appVersion forKey:@"appVersion"];//存储手机应用版本
    [defaulut synchronize];
    if (![lastVersion isEqualToString:appVersion]) {//版本号不一致时 重置次数
        [defaulut setInteger:1 forKey:@"HAOPING"];//存储次数
    }
    //判断版本号,且启动过15次
    if ([lastVersion isEqualToString:appVersion] && num == 15) {
        return true;
    }
    return false;
}
#pragma mark - 修改头像
-(void)changeThePicture
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogIn];
    }else{
        LSZPersonalInformationMg * information = nil;
        information = self.informationMg.mutDataArray[0];
        LSZPersonalInformationPageVC * vc = [[LSZPersonalInformationPageVC alloc]init];
        vc.uid = information.uid;
        vc.imageViewHeader = information.avatar;
        vc.isMine = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end
